public class num606 {
    /**
     * 先序遍历创建字符串
     * @param root
     * @return
     */
    StringBuilder sb = new StringBuilder();
    public String tree2str(TreeNode root) {
        if(root == null){
            return null;
        }
        sb.append(root.val);
        if(root.left != null){
            sb.append("(");
            tree2str(root.left);
            sb.append(")");
        }else{
            if(root.right != null){
                sb.append("()");
            }
        }
        if(root.right != null){
            sb.append("(");
            tree2str(root.right);
            sb.append(")");
        }
        return sb.toString();
    }
}
